//
//  ImageViewViewController.m
//  GCD
//
//  Created by fangyuan ding on 2020/8/11.
//  Copyright © 2020 fangyuan ding. All rights reserved.
//

#import "LayerViewController.h"

@interface LayerViewController ()

@end

@implementation LayerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   //创建了一个字符承载视图
    UIView *textView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 50)];
    CATextLayer *text = [CATextLayer layer];
    text.frame = textView.frame;
    text.string = @"CAText";
    //文字前景色和背景色
    text.foregroundColor = [UIColor whiteColor].CGColor;
    text.backgroundColor = [UIColor blackColor].CGColor;
    //文字超出视图边界剪裁
    text.wrapped = YES;
    //文字字体
    text.font = (__bridge CFTypeRef)[UIFont systemFontOfSize:30].fontName;
    //文字居中
    text.alignmentMode = kCAAlignmentCenter;
    //适应屏幕Retina分辨率，防止像素化导致模糊
    text.contentsScale = [[UIScreen mainScreen] scale];
    [textView.layer addSublayer:text];
    [self.view addSubview:textView];
    [self drawRect:CGRectMake(100, 100, 200, 200)];
    
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
    UIImage *image = [UIImage imageNamed:@"icon"];
    
    
}

- (void)drawRect:(CGRect)rect{
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:100 startAngle:0 endAngle:M_PI_2 clockwise:YES];
    path.lineWidth = 5;
    path.lineCapStyle = kCGLineCapRound;
    path.lineJoinStyle = kCGLineCapRound;
    [path stroke];
}


//绘制UIImage矩形圆角
//- (UIImage *)imageWithCornerRadius:(CGFloat)radius ofSize:(CGSize)size{
//    CGRect rect = (CGRect){0.f,0.f,size};
//    UIGraphicsBeginImageContextWithOptions(size, NO, UIScreen.mainScreen.scale);
//    CGContextAddPath(UIGraphicsGetCurrentContext(), [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
//    CGContextClip(UIGraphicsGetCurrentContext());
//    [self drawInRect:rect];
//    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    return image;
//    
//}
@end
